Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es-main

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-main

Test if an ES module is run directly (require.main replacement)

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
210K
decreased by-28.4%
Maintainers
1
Weekly downloads
 
Created

What is es-main?

The es-main npm package is a utility that helps determine if a module is being run directly or being imported as a module. This can be particularly useful for writing scripts that can be both executed directly and imported as part of a larger application.

What are es-main's main functionalities?

Check if a module is the main module

This feature allows you to check if the current module is being run directly or being imported. The code sample demonstrates how to use the es-main package to print a message based on the module's execution context.

const esMain = require('es-main');

if (esMain(import.meta)) {
  console.log('This module is being run directly.');
} else {
  console.log('This module is being imported.');
}

Other packages similar to es-main

Keywords

FAQs

Package last updated on 02 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc